package com.xbongbong.pro.message.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.paas.enums.EnableEnum;
import com.xbongbong.paas.log.constant.LogMemoConstant;
import com.xbongbong.paas.log.entity.OperateLogEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.JsonHelperUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.log.pojo.DetailLogPojo;
import com.xbongbong.pro.message.enums.PushObjectTypeEnum;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.enums.WorkOrderV2PushTypeEnum;
import com.xbongbong.pro.message.pojo.MessageSetDetailPojo;
import com.xbongbong.pro.message.pojo.dto.MessageSetDetailDTO;
import com.xbongbong.pro.message.pojo.dto.MessageSetEnableDTO;
import com.xbongbong.pro.message.pojo.dto.MessageSetSaveDTO;
import com.xbongbong.pro.message.pojo.vo.MessageSetDetailVO;
import com.xbongbong.pro.message.pojo.vo.MessageSetEnableVO;
import com.xbongbong.pro.message.pojo.vo.MessageSetSaveVO;
import com.xbongbong.pro.message.pojo.vo.PushSetVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.OperateModuleTypeEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.sys.domain.entity.CompanyEntity;
import com.xbongbong.sys.domain.entity.UserEntity;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 新工单(V2.0)消息设置服务实现类
 *
 * @author LiZhikang
 * @date 2022/11/1 17:03
 */
@Service
public class WorkOrderV2MessageSetServiceImpl extends AbstractMessageSetService {

    @Override
    public List<String> alias() {
        return Collections.singletonList(XbbRefTypeEnum.WORK_ORDER_V2_CENTER.getAlias());
    }

    @Override
    public String initSetDetailList() throws Exception {
        Map<String, Object> defaultParam = new HashMap<>(2);
        defaultParam.put(StringConstant.CORPID, StringConstant.ZERO);
        defaultParam.put(StringConstant.TYPE, XbbRefTypeEnum.WORK_ORDER_V2.getCode());
        List<PushSetEntity> entitys = pushSetModel.findEntitys(defaultParam);
        if (entitys.size() == 0) {
            initWorkOrderV2DetailList();
        }
        return StringConstant.SUCCESS;
    }

    @Override
    public MessageSetDetailVO getSetDetailList(MessageSetDetailDTO messageSetDetailDTO) throws Exception {
        List<MessageSetDetailPojo> messageSetDetailPojos = new ArrayList<>();
        Integer typeInt = messageSetDetailDTO.getSaasIds().get(0).intValue();
        typeInt = XbbRefTypeEnum.transferBusinessType4Distributor(typeInt, messageSetDetailDTO.getDistributorMark());
        String alias = PushTypeEnum.getByCode(typeInt).getAlias();
        if (!Objects.equals(alias, PushTypeEnum.UNKNOWN.getAlias())) {
            String methodName = "getMessageSetSaas" + alias.substring(0, 1).toUpperCase() + alias.substring(1) + "DetailList";
            Method method = this.getClass().getDeclaredMethod(methodName, String.class, List.class, Integer.class);
            method.invoke(this, messageSetDetailDTO.getCorpid(), messageSetDetailPojos, typeInt);
        }
        return new MessageSetDetailVO(messageSetDetailPojos);
    }

    private void getMessageSetSaasWorkOrderV2PushDetailList(String corpid, List<MessageSetDetailPojo> messageSetDetailPojos, Integer typeInt){
        //获取默认数据
        Map<String, Object> defaultParam = new HashMap<>(2);
        defaultParam.put(StringConstant.CORPID, StringConstant.ZERO);
        defaultParam.put(StringConstant.TYPE, XbbRefTypeEnum.WORK_ORDER_V2.getCode());
        List<PushSetEntity> defaultEntites = pushSetModel.findEntitys(defaultParam);
        //获取当前公司数据
        Map<String, Object> currentParam = new HashMap<>(2);
        currentParam.put(StringConstant.CORPID, corpid);
        currentParam.put(StringConstant.TYPE, XbbRefTypeEnum.WORK_ORDER_V2.getCode());
        List<PushSetEntity> currentEntities = pushSetModel.findEntitys(currentParam);
        //若公司已有部分数据,则覆盖这一部分数据,其余保持默认
        Map<Integer, PushSetEntity> currentMap = new HashMap<>(15);
        currentEntities.forEach(entity -> currentMap.put(entity.getSubType(), entity));
        List<PushSetVO> pushSetVOList = defaultEntites.stream().map(entity -> {
            PushSetVO vo = new PushSetVO();
            PushSetEntity currentEntity = currentMap.get(entity.getSubType());
            if (Objects.isNull(currentEntity)) {
                BeanUtil.copyProperties(entity, vo);
                vo.setId(BasicConstant.ZERO);
            } else {
                BeanUtil.copyProperties(currentEntity, vo);
            }
            WorkOrderV2PushTypeEnum pushTypeEnum = WorkOrderV2PushTypeEnum.getBySubCode(vo.getSubType());
            vo.setTitle(pushTypeEnum.getTitle());
            vo.setContent(pushTypeEnum.getContent());
            vo.setModule(pushTypeEnum.getModule());
            return vo;
        }).collect(Collectors.toList());
        //拼装数据
        MessageSetDetailPojo detailPojo1 = new MessageSetDetailPojo();
        detailPojo1.setTitle("工单中心常规推送");
        detailPojo1.setValue(pushSetVOList.stream().filter(vo -> vo.getModule() == 1).collect(Collectors.toList()));
        messageSetDetailPojos.add(detailPojo1);
        MessageSetDetailPojo detailPojo2 = new MessageSetDetailPojo();
        detailPojo2.setTitle("工单状态变更");
        detailPojo2.setValue(pushSetVOList.stream().filter(vo -> vo.getModule() == 2).collect(Collectors.toList()));
        messageSetDetailPojos.add(detailPojo2);
    }

    @Override
    public MessageSetSaveVO saveMessageSet(MessageSetSaveDTO messageSetSaveDTO) throws Exception {
        MessageSetSaveVO messageSetSaveVo = new MessageSetSaveVO();
        Long id = messageSetSaveDTO.getId();
        PushSetEntity pushSetEntity = new PushSetEntity();
        PushSetEntity oldPushSetEntity = null;
        if (Objects.equals(id, 0L)) {
            //新建
            pushSetEntity = new PushSetEntity();
            pushSetEntity.setCorpid(messageSetSaveDTO.getCorpid());
            pushSetEntity.setAttrEntity(messageSetSaveDTO.getAttrEntity());
            pushSetEntity.setType(messageSetSaveDTO.getType());
            pushSetEntity.setSubType(messageSetSaveDTO.getSubType());
            pushSetEntity.setEnable(messageSetSaveDTO.getEnable());
            pushSetEntity.setRefEntity(messageSetSaveDTO.getRefEntity());
            pushSetEntity.setTemplateId(messageSetSaveDTO.getTemplateId());
        } else {
            //编辑
            oldPushSetEntity = pushSetModel.getByKey(messageSetSaveDTO.getId(), messageSetSaveDTO.getCorpid());
            if (oldPushSetEntity == null) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018, SystemErrorCodeEnum.API_ERROR_100018.getMsg());
            }
            BeanUtil.copyProperties(oldPushSetEntity, pushSetEntity);
        }
        pushSetEntity.setPushObject(messageSetSaveDTO.getPushObject());
        pushSetEntity.setPushTime(messageSetSaveDTO.getPushTime());
        messageSetSaveVo.setId(pushSetModel.save(pushSetEntity));

        if (Objects.equals(pushSetEntity.getEnable(), 1)) {
            CompanyEntity companyEntity = companyModel.getByKey(messageSetSaveDTO.getCorpid());
            companyEntity.setIsPushMessage(1);
            companyModel.update(companyEntity);
        }

        // 日志
        WorkOrderV2PushTypeEnum pushTypeEnum = WorkOrderV2PushTypeEnum.getBySubCode(pushSetEntity.getSubType());
        String memo;
        if (Objects.equals(id, 0L)) {
            //新增
            memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.MESSAGE_PUSH_SET_LOG_MEMO_ADD_SET), messageSetSaveDTO.getLoginUserName(), pushTypeEnum.getTitle());
            OperateLogEntity logEntity = new OperateLogEntity(messageSetSaveDTO.getCorpid(), messageSetSaveDTO.getUserId(), messageSetSaveDTO.getLoginUserName(), OperateModuleTypeEnum.MESASAGE_PUSH_SET,
                    OperateTypeEnum.NEW, pushSetEntity.getId().toString(), pushTypeEnum.getTitle(), memo, messageSetSaveDTO.getHttpHeader(), null);
            operateLogModel.insert(logEntity);
        } else {
            //编辑
            JSONObject oldObj = JsonHelperUtil.parseObject(JSONObject.toJSONString(oldPushSetEntity));
            JSONObject newObj = JsonHelperUtil.parseObject(JSONObject.toJSONString(pushSetEntity));

            memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.MESSAGE_PUSH_SET_LOG_MEMO_EDIT_SET), messageSetSaveDTO.getLoginUserName(), pushTypeEnum.getTitle());
            List<DetailLogPojo> detailArr = logHelp.getDetailArr4Normal(messageSetSaveDTO.getCorpid(), OperateModuleTypeEnum.MESASAGE_PUSH_SET, oldObj, newObj);
            mongoLogHelp.buildLog4DetailArr(detailArr, messageSetSaveDTO.getCorpid(), messageSetSaveDTO.getUserId(), messageSetSaveDTO.getLoginUserName(),
                    OperateModuleTypeEnum.MESASAGE_PUSH_SET, OperateTypeEnum.EDIT, id.toString(), pushTypeEnum.getTitle(), memo, messageSetSaveDTO.getHttpHeader());
        }
        return messageSetSaveVo;
    }

    @Override
    public MessageSetEnableVO enableMessageSet(MessageSetEnableDTO messageSetEnableDTO) throws Exception {
        MessageSetEnableVO messageSetEnableVO = new MessageSetEnableVO();
        PushSetEntity pushSetEntity = pushSetModel.getByKey(messageSetEnableDTO.getId(), messageSetEnableDTO.getCorpid());
        if (pushSetEntity == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100018, SystemErrorCodeEnum.API_ERROR_100018.getMsg());
        }
        pushSetEntity.setEnable(messageSetEnableDTO.getEnable());
        messageSetEnableVO.setId(pushSetModel.save(pushSetEntity));

        // 日志
        WorkOrderV2PushTypeEnum pushTypeEnum = WorkOrderV2PushTypeEnum.getBySubCode(pushSetEntity.getSubType());
        OperateTypeEnum operateTypeEnum = (Objects.equals(BasicConstant.NO_USE, messageSetEnableDTO.getEnable())) ? OperateTypeEnum.CLOSE : OperateTypeEnum.ENABLE;
        String enableStr = (Objects.equals(BasicConstant.NO_USE, messageSetEnableDTO.getEnable())) ? EnableEnum.CLOSE.getMemo() : EnableEnum.OPEN.getMemo();
        String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.MESSAGE_PUSH_SET_LOG_MEMO_ENABLE), messageSetEnableDTO.getLoginUserName() + enableStr, pushTypeEnum.getTitle());
        OperateLogEntity logEntity = new OperateLogEntity(messageSetEnableDTO.getCorpid(), messageSetEnableDTO.getUserId(), messageSetEnableDTO.getLoginUserName(), OperateModuleTypeEnum.MESASAGE_PUSH_SET,
                operateTypeEnum, pushSetEntity.getId().toString(), pushTypeEnum.getTitle(), memo, messageSetEnableDTO.getHttpHeader(), null);
        operateLogModel.insert(logEntity);
        return messageSetEnableVO;
    }

    @Override
    public List<String> getUserIdListByPushSetRule(String corpid, Integer type, Integer subType, UserEntity userEntity, Entity entity) throws Exception {
        //TODO 目前该类没办法和WorkOrderV2MessageSetServiceImpl合并,原因:工单extends抽象类,Pro那边拿不到对应的Bean,但是如果实现类放Pro那边又没办法引用工单的POJO类
        //TODO 消息推送代码重构二期合并
        return null;
    }

    private void initWorkOrderV2DetailList() throws XbbException {
        //创建人
        JSONObject creator = new JSONObject();
        creator.put("name", PushObjectTypeEnum.CREATOR.getName());
        creator.put("enable", 1);
        creator.put("alias", PushObjectTypeEnum.CREATOR.getAlias());
        //负责人
        JSONObject owner = new JSONObject();
        owner.put("name", PushObjectTypeEnum.MAINUSER.getName());
        owner.put("enable", 1);
        owner.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
        //协同人
        JSONObject collaborator = new JSONObject();
        collaborator.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
        collaborator.put("enable", 1);
        collaborator.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());

        //工单新建
        PushSetEntity pushSetEntity1 = new PushSetEntity();
        pushSetEntity1.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_ADD.getSubCode());
        pushSetEntity1.setPushObject(initPushObjectAdd());
        initBaseParam(pushSetEntity1);
        //工单分配
        PushSetEntity pushSetEntity2 = new PushSetEntity();
        pushSetEntity2.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_ALLOCATE.getSubCode());
        pushSetEntity2.setPushObject(initPushObject());
        initBaseParam(pushSetEntity2);
        //工单移交
        PushSetEntity pushSetEntity3 = new PushSetEntity();
        pushSetEntity3.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_TRANSFER.getSubCode());
        pushSetEntity3.setPushObject(initPushObject());
        initBaseParam(pushSetEntity3);
        //工单团队
        PushSetEntity pushSetEntity4 = new PushSetEntity();
        pushSetEntity4.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_TEAM.getSubCode());
        pushSetEntity4.setPushObject(initPushObjectTeam());
        initBaseParam(pushSetEntity4);
        //工单删除
        PushSetEntity pushSetEntity5 = new PushSetEntity();
        pushSetEntity5.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_DELETE.getSubCode());
        pushSetEntity5.setPushObject(initPushObjectDelete());
        initBaseParam(pushSetEntity5);
        //工单异常
        PushSetEntity pushSetEntity6 = new PushSetEntity();
        pushSetEntity6.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_ABNORMAL.getSubCode());
        pushSetEntity6.setPushObject(initPushObject());
        initBaseParam(pushSetEntity6);
        //工单接受
        PushSetEntity pushSetEntity7 = new PushSetEntity();
        pushSetEntity7.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_RECEIVE.getSubCode());
        pushSetEntity7.setPushObject(initPushObject());
        initBaseParam(pushSetEntity7);
        //工单开始
        PushSetEntity pushSetEntity8 = new PushSetEntity();
        pushSetEntity8.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_START.getSubCode());
        pushSetEntity8.setPushObject(initPushObject());
        initBaseParam(pushSetEntity8);
        //工单完成
        PushSetEntity pushSetEntity9 = new PushSetEntity();
        pushSetEntity9.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_FINISH.getSubCode());
        pushSetEntity9.setPushObject(initPushObject());
        initBaseParam(pushSetEntity9);
        //工单取消
        PushSetEntity pushSetEntity10 = new PushSetEntity();
        pushSetEntity10.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_CANCEL.getSubCode());
        pushSetEntity10.setPushObject(initPushObject());
        initBaseParam(pushSetEntity10);
        //工单结算
        PushSetEntity pushSetEntity11 = new PushSetEntity();
        pushSetEntity11.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_SETTLE.getSubCode());
        pushSetEntity11.setPushObject(initPushObject());
        initBaseParam(pushSetEntity11);
        //工单回访
        PushSetEntity pushSetEntity12 = new PushSetEntity();
        pushSetEntity12.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_VISIT.getSubCode());
        pushSetEntity12.setPushObject(initPushObject());
        initBaseParam(pushSetEntity12);
        //工单抢单
        PushSetEntity pushSetEntity13 = new PushSetEntity();
        pushSetEntity13.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_GRAB.getSubCode());
        pushSetEntity13.setPushObject(initPushObject());
        initBaseParam(pushSetEntity13);
        //工单重启
        PushSetEntity pushSetEntity14 = new PushSetEntity();
        pushSetEntity14.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_RESTART.getSubCode());
        pushSetEntity14.setPushObject(initPushObject());
        initBaseParam(pushSetEntity14);
        //工单回退
        PushSetEntity pushSetEntity15 = new PushSetEntity();
        pushSetEntity15.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_BACK.getSubCode());
        pushSetEntity15.setPushObject(initPushObject());
        initBaseParam(pushSetEntity15);
        //工单拒绝
        PushSetEntity pushSetEntity16 = new PushSetEntity();
        pushSetEntity16.setSubType(WorkOrderV2PushTypeEnum.WORK_ORDER_V2_REFUSE.getSubCode());
        pushSetEntity16.setPushObject(initPushObject());
        initBaseParam(pushSetEntity16);

        //插入数据库
        pushSetModel.insert(pushSetEntity1);
        pushSetModel.insert(pushSetEntity2);
        pushSetModel.insert(pushSetEntity3);
        pushSetModel.insert(pushSetEntity4);
        pushSetModel.insert(pushSetEntity5);
        pushSetModel.insert(pushSetEntity6);
        pushSetModel.insert(pushSetEntity7);
        pushSetModel.insert(pushSetEntity8);
        pushSetModel.insert(pushSetEntity9);
        pushSetModel.insert(pushSetEntity10);
        pushSetModel.insert(pushSetEntity11);
        pushSetModel.insert(pushSetEntity12);
        pushSetModel.insert(pushSetEntity13);
        pushSetModel.insert(pushSetEntity14);
        pushSetModel.insert(pushSetEntity15);
        pushSetModel.insert(pushSetEntity16);

    }

    private String initPushObject() {
        JSONObject pushObject = new JSONObject();
        //创建人,负责人,协同人
        JSONArray typeArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", PushObjectTypeEnum.CREATOR.getName());
        jsonObject.put("enable", 0);
        jsonObject.put("alias", PushObjectTypeEnum.CREATOR.getAlias());
        typeArray.add(jsonObject);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
        jsonObject1.put("enable", 1);
        jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
        typeArray.add(jsonObject1);
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
        jsonObject2.put("enable", 1);
        jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
        typeArray.add(jsonObject2);
        pushObject.put("type", typeArray);
        //上级主管
        JSONObject managerObject = new JSONObject();
        managerObject.put("enable", 0);
        managerObject.put("value", new ArrayList<>());
        pushObject.put("manager", managerObject);
        //多选组件
        JSONObject multiObject = new JSONObject();
        multiObject.put("enable", 0);
        multiObject.put("value", new ArrayList<>());
        pushObject.put("multi", multiObject);
        return pushObject.toJSONString();
    }

    private String initPushObjectAdd() {
        JSONObject pushObject = new JSONObject();
        //创建人,负责人,协同人
        JSONArray typeArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", PushObjectTypeEnum.CREATOR.getName());
        jsonObject.put("enable", 0);
        jsonObject.put("alias", PushObjectTypeEnum.CREATOR.getAlias());
        typeArray.add(jsonObject);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
        jsonObject1.put("enable", 0);
        jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
        typeArray.add(jsonObject1);
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
        jsonObject2.put("enable", 1);
        jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
        typeArray.add(jsonObject2);
        pushObject.put("type", typeArray);
        //上级主管
        JSONObject managerObject = new JSONObject();
        managerObject.put("enable", 0);
        managerObject.put("value", new ArrayList<>());
        pushObject.put("manager", managerObject);
        //多选组件
        JSONObject multiObject = new JSONObject();
        multiObject.put("enable", 0);
        multiObject.put("value", new ArrayList<>());
        pushObject.put("multi", multiObject);
        return pushObject.toJSONString();
    }

    private String initPushObjectTeam() {
        JSONObject pushObject = new JSONObject();
        //创建人,负责人,协同人
        JSONArray typeArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", PushObjectTypeEnum.CREATOR.getName());
        jsonObject.put("enable", 0);
        jsonObject.put("alias", PushObjectTypeEnum.CREATOR.getAlias());
        typeArray.add(jsonObject);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
        jsonObject1.put("enable", 0);
        jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
        typeArray.add(jsonObject1);
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
        jsonObject2.put("enable", 1);
        jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
        typeArray.add(jsonObject2);
        pushObject.put("type", typeArray);
        //上级主管
        JSONObject managerObject = new JSONObject();
        managerObject.put("enable", 0);
        managerObject.put("value", new ArrayList<>());
        pushObject.put("manager", managerObject);
        //多选组件
        JSONObject multiObject = new JSONObject();
        multiObject.put("enable", 0);
        multiObject.put("value", new ArrayList<>());
        pushObject.put("multi", multiObject);
        return pushObject.toJSONString();
    }

    private String initPushObjectDelete() {
        JSONObject pushObject = new JSONObject();
        //创建人,负责人,协同人
        JSONArray typeArray = new JSONArray();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", PushObjectTypeEnum.CREATOR.getName());
        jsonObject.put("enable", 1);
        jsonObject.put("alias", PushObjectTypeEnum.CREATOR.getAlias());
        typeArray.add(jsonObject);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name", PushObjectTypeEnum.MAINUSER.getName());
        jsonObject1.put("enable", 1);
        jsonObject1.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
        typeArray.add(jsonObject1);
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
        jsonObject2.put("enable", 0);
        jsonObject2.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
        typeArray.add(jsonObject2);
        pushObject.put("type", typeArray);
        //上级主管
        JSONObject managerObject = new JSONObject();
        managerObject.put("enable", 0);
        managerObject.put("value", new ArrayList<>());
        pushObject.put("manager", managerObject);
        //多选组件
        JSONObject multiObject = new JSONObject();
        multiObject.put("enable", 0);
        multiObject.put("value", new ArrayList<>());
        pushObject.put("multi", multiObject);
        return pushObject.toJSONString();
    }

    private void initBaseParam(PushSetEntity pushSetEntity) {
        pushSetEntity.setCorpid("0");
        pushSetEntity.setRefEntity(0);
        pushSetEntity.setAttrEntity("");
        pushSetEntity.setType(XbbRefTypeEnum.WORK_ORDER_V2.getCode());
        pushSetEntity.setPushTime("{}");
        pushSetEntity.setEnable(0);
        pushSetEntity.setDel(0);
        pushSetEntity.setTemplateId((long) 0);
    }
}
